using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using DataAccess;
using DataTransferObject;

namespace Business
{
    public enum SachBUSResult
    {
        OK,
        DKCBERROR,
        TRANGTHAICERROR,
        MATUASACHCERROR,
        MAVTCERROR,
        MAHONGCERROR,
        DAOERROR
    }

    public class clsSachBUS
    {
        //Fields.
        private clsSachDAO SachDAO;

        //Constructors.
        public clsSachBUS()
        {
            this.SachDAO = new clsSachDAO();
        }

        #region Methods


        //Cập nhật lại trạng thái chưa mượn cho quyển sách.
        public bool CapNhatTrangThaiChuaMuonChoSach(String DKCB, String MaHong)
        {
            return SachDAO.CapNhatTrangThaiChuaMuonChoSach(DKCB, MaHong);
        }

        public long TimGiaCuaMotQuyenSachTheoMa(String DKCB)
        {
            return SachDAO.TimGiaCuaMotQuyenSachTheoMa(DKCB);
        }

        public String TimTenTuaSachTheoDKCB(String DKCB)
        {
            return SachDAO.TimTenSachTheMa(DKCB);
        }

        public bool CapNhatTrangThaiDaMuonChoSach(String DKCB)
        {
            return SachDAO.UpdateDaMuon(DKCB);
        }

        public DataTable TimSachChuMuonTheMa(String MaSach)
        {
            return SachDAO.TimSachChuaMuonTheMa(MaSach);
        }

        public DataTable DanhSachSachReference()
        {
            return this.SachDAO.SelectAllReference();
        }

        public DataTable DanhSachSach()
        {
            return this.SachDAO.SelectAll();
        }

        public DataTable LayTTSachThongKe()
        {
            return this.SachDAO.LayThongKeSach();
        }

        public DataTable LaySachConTrongKho()
        {
            return this.SachDAO.LayThongKeSachConLai();
        }

        public DataTable ThongKeSachDaMuon()
        {
            return this.SachDAO.LayThonKeSachDaMuon();
        }
        public DataTable ThongKeSachMuonItNhat()
        {
            return this.SachDAO.LayThongKeSachMuonitNhat();
        }
        public DataTable ThongKeSachMuonNhieuNhat()
        {
            return this.SachDAO.LayThongKeSachMuonNhieuNhat();
        }
        public SachBUSResult ThemSach(clsSachDTO obj)
        {
            if (!this.SachDAO.Insert(obj))
                return SachBUSResult.DAOERROR;
            return SachBUSResult.OK;
        }

        public SachBUSResult SuaSach(clsSachDTO obj)
        {
            if (!this.SachDAO.Update(obj))
                return SachBUSResult.DAOERROR;
            return SachBUSResult.OK;
        }

        public SachBUSResult XoaSach(clsSachDTO obj)
        {
            if (!this.SachDAO.Delete(obj))
                return SachBUSResult.DAOERROR;
            return SachBUSResult.OK;
        }
        #endregion
    }
}

